﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Enough.Helper
{
    public static class GlobalizationHelper
    {
        private static ResourceManager _resourceLoader;

        public static string Localize(string resourceName, params object[] parameters)
        {
            if (_resourceLoader == null)
            {
                Type type = Application.Current.GetType();
                string baseName = type.Namespace + ".Resources.AppResources"; // Something like: YourApp.Resources.AppResources
                Assembly assembly = type.Assembly;
                _resourceLoader = new ResourceManager(baseName, assembly);
            }
            string translation = _resourceLoader.GetString(resourceName);
            if (translation != null && parameters != null && parameters.Length > 0)
            {
                translation = string.Format(translation, parameters);
            }
            return translation;
        }
    }
}
